/**
 * 更新菜单
 * @url admin/system/menu/sys/update
 * @description 更新菜单信息
 */
module.exports = {
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '更新成功' };
		
		// 业务逻辑开始-----------------------------------------------------------
		let {
			_id,
			name,
			url,
			parent_id,
			sort,
			enable
		} = data;
		
		if (!_id) {
			return { code: -1, msg: '菜单ID不能为空' };
		}
		
		// 构建更新数据
		let updateData = {};
		if (name !== undefined) updateData.name = name;
		if (url !== undefined) updateData.url = url;
		if (parent_id !== undefined) updateData.parent_id = parent_id;
		if (sort !== undefined) updateData.sort = sort;
		if (enable !== undefined) updateData.enable = enable;
		
		// 更新菜单信息
		await db.collection('opendb-admin-menus').doc(_id).update(updateData);
		
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}

